/*
import 'package:flutter/material.dart';
import 'package:vr/vr.dart';

void main() => runApp(MaterialApp(home: MyApp()));

class MyApp extends StatelessWidget {

  BuildContext _context;

  @override
  Widget build(BuildContext context) {
    _context = context;
    return Scaffold(
      body: Container(
        height: 600,
        margin: EdgeInsets.only(left: 20, top: 100),
        child: Vr(
          onVrCreated: _onTextViewCreated,
        ),
      )
    );
  }

  void _onTextViewCreated(VrController controller) async {
    */
/*var result = await controller.setText('原生组件，点击调用flutter方法');
    print(result as String);
    controller.addNativeMethod(_route);*//*

  }

  void _route(String params) {
    Navigator.of(_context).push(
      new MaterialPageRoute(
          builder: (BuildContext context) {
            return new MaterialApp(
              title: 'Welcome to Flutter',
              home: new Scaffold(
                appBar: new AppBar(
                  title: new Text('Welcome to Flutter'),
                ),
                body: new Center(
                  child: new Text(params),
                ),
              ),
            );
          }
      ),
    );
  }
}*/


import 'package:flutter/material.dart';
import 'package:vr/vr.dart';

void main() => runApp(MaterialApp(home: VrNativeContainer()));

class VrNativeContainer extends StatelessWidget {

  static String routeName = 'flutter://VrNativeContainer';

  BuildContext _context;

  @override
  Widget build(BuildContext context) {
    _context = context;
//    Map<String, dynamic> arguments = ModalRoute.of(context).settings.arguments;
//    final initialPath = arguments["url"] as String;
//    final hiddenTitle = arguments["hiddenTitle"] as bool;
//    final fullScreen = arguments["fullScreen"] as bool;
//    final isFromReceive = arguments["isFromReceive"] as bool;
//    print("initial path is : ${initialPath}");
//    if (initialPath == null || initialPath.length <= 0){
//      return Scaffold(
//        appBar: AppBar(),
//        body: Center(
//          child: Text("全景不存在"),
//        ),
//      );
//    }
    return Scaffold(
      body: Vr(
        initialPath: 'https://test.vr.asman.com.cn/vr.html?schemeId=100001&vrType=1&token=15TKtt:d3f61049f904447f8736760adedbead5&roomId=100001&groupId=df636193c38b4ef79b3e366bdcab724f&',
        hiddenTitle: 1,
        fullScreen: 1,
        isFromReceive: 1,
        onVrCreated: _onVrCreated,
      ),
    );
  }

  void _onVrCreated(VrController controller) async {
    // 注册 flutter 的方法给原生调用
    controller.addNativeMethod(
        routeToDecorateDetail: routeToDecorateDetail,
        onGoBack: _onGoBack
    );
  }

  void routeToDecorateDetail(num schemeId, num workId, Map<String, dynamic> hotspots) {
    /*Navigator.pushNamed(_context, DecorateDetail.routeName, arguments: {
      schemeId: schemeId,
      workId: workId,
      hotspots: hotspots,
    });*/
  }

  void _onGoBack(){
    Navigator.pop(_context);
  }
}

//import 'package:flutter/material.dart';
//import 'package:vr/answer.dart';
//import 'package:vr/model/scheme_info_detail_data.dart';
//
//void main() => runApp(MaterialApp(home: AnswerNativeContainer()));
//
//class AnswerNativeContainer extends StatefulWidget {
//
//  static String routeName = 'flutter://AnswerNativeContainer';
//
//  @override
//  State<AnswerNativeContainer> createState() => _AnswerNativeContainer();
//}
//
//class _AnswerNativeContainer extends State<AnswerNativeContainer> {
//
//  SchemeInfoDetailData _schemeInfoDetailData = null;
//
//  BuildContext _context;
//
//  @override
//  void initState() {
//    super.initState();
//
//    // 监听 socket 事件
//    EventBusInstance.on(SocketHangUpEvent, (arg) {
//      _onGoBack();
//    });
//    EventBusInstance.on(SocketAnswerTimeout, (arg) {
//      _onGoBack();
//    });
//  }
//
//  @override
//  Widget build(BuildContext context) {
//    _context = context;
//
//    Map<String, dynamic> arguments = ModalRoute.of(context).settings.arguments;
//    final schemeId = 100001;
//    final roomId = 100001;
//    final headUrl = null;
//    final name = "18000000000";
//    final userId = 1003300616;
//    final accountId = 1003300216601705;
//    final vrType = 1;
//    final groupId = "df636193c38b4ef79b3e366bdcab724f";
//    _schemeInfoDetailData = SchemeInfoDetailData(
//        1003301203,
//      "15000000055",
//      "55号",
//      "https://img.asman.com.cn/assets/1578452769983_98917.png",
//        127.0,
//      "华夏四季",
//      2,
//      100001,
//      "https://asman-img.oss-cn-hangzhou.aliyuncs.com/9448607_145742365000_2_9f92e84b40ff4d248fc68687e29b00a1.jpg",
//      -1,
//      "https://img.asman.com.cn/3a921ef745f5c79347abfb79177c3d9c.jpg",
//      "https://pano.asman.com.cn/test/scheme/100001/pano",
//      null,
//      "",
//        10485080,
//      null,
//      "牛牛搭租户方案",
//      "新古典",
//      1,
//      "",
//      1,
//      HouseParams(2, 2, 3, 4, 5)
//    );
//
//
//    if (_schemeInfoDetailData == null) {
//      _getSchemeInfoDetail(schemeId, vrType);
//      return Container();
//    }
//    return Scaffold(
//      body: Answer(
//        onAnswerCreated: _onAnswerCreated,
//        schemeInfoDetailData: _schemeInfoDetailData,
//        schemeId: schemeId,
//        roomId: roomId,
//        headUrl: headUrl,
//        name: name,
//        userId: userId,
//        accountId: accountId,
//        vrType: vrType,
//        groupId: groupId,
//      ),
//    );
//  }
//
//  void _onAnswerCreated(AnswerController controller) async {
//    // 注册 flutter 的方法给原生调用
//    controller.addNativeMethod(
//      onGoBack: _onGoBack,
//    );
//  }
//
//  void _onGoBack(){
//    EventBusInstance.off(SocketHangUpEvent);
//    EventBusInstance.off(SocketAnswerTimeout);
//    Navigator.pop(_context);
//  }
//
//  void _getSchemeInfoDetail(int schemeId, int vrType) async {
//    Response res = await DioUtils.dio.then((value) => value.get(ApiPath.getSchemeInfoDetail, queryParameters: {
//      "schemeId": schemeId,
//      "vrType": vrType,
//    }));
//    setState(() {
//      _schemeInfoDetailData = SchemeInfoDetailData.fromJson(res.data);
//    });
//  }
//
//}
